def s(n):
    c = True
    if len(str(n)) != 3:
        c = False
    for d in range(2, int(n ** 0.5) + 1):
        if n % d == 0:
            c = False
            break
    return c


di = {
    'zero': 0,
    'one': 1,
    'two': 2,
    'three': 3,
    'four': 4,
    'five': 5,
    'six': 6,
    'seven': 7,
    'eight': 8,
    'nine': 9
}
a = input().split()
if len(a) != 3 or not (set(a) <= set(di.keys())):
    print('Wrong input')
    exit()
a = di[a[0]] * 100 + di[a[1]] * 10 + di[a[2]]
if s(a):
    print(a)
else:
    pr = a
    while not s(pr):
        pr += 1
    pl = a
    while not s(pl):
        pl -= 1
    if abs(a - pr) >= abs(a - pl):
        print(pl)
    else:
        print(pr)
